package org.jimmy.tang.io;

import java.io.Console;

/**
 * @author jimmy
 * 
 */
public class ConsoleDemo {
    public static void main(String[] args) {
        Console cons;
        char[] passwd = null;
        String username = null;

        if (((cons = System.console()) != null)
                && ((username = cons.readLine("%s", "User name:")) != null)
                && ((passwd = cons.readPassword("%s", "Password:")) != null)) {
            System.out.println("User name:" + username);
            String password = new String(passwd);
            System.out.println("Password:" + password);
        } else {
            System.out.println("The console is unavailable ");
        }

    }
}
